/*
    link.me - Linker Component
 */

Me.load({ 
    targets: {
        link: {
            description: 'Link Editor Program',
            path: function(target) {
                let path: Path
                if (target.withpath) {
                    path = target.withpath
                } else {
                    if (me.platform.like == 'windows') {
                        path = 'link.exe'
                    } else if (me.platform.os == 'vxworks') {
                        path = 'ld' + me.targets.compiler.vxarch
                    } else {
                        path = 'ld'
                    }
                }
                if (me.options.gen) {
                    if (me.platform.dev == 'windows-x86' && me.platform.arch == 'x64') {
                        if (!path.dirname.join('cvtres.exe').exists) {
                            stderr.writeLine()
                            trace('Warn', 'Cannot find cvtres.exe in ' + path.dirname + '. Linking may not be successful.')
                            stderr.writeLine('This is a known issue with a missing cvtres.exe in the x86_64 VS directory.')
                            stderr.writeLine('Please upgrade Visual Studio.\n')
                        }
                    }
                } else {
                    path = probe(path, {fullpath: true, search: me.targets.compiler.search, default: path})
                }
                return path
            },
            ifdef: ['compiler'],
        },
    }
})
